﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;

namespace JYM.Common.Web
{
    /// <summary>
    /// 枚举工具类
    /// </summary>
    public class EnumHelper : JYM.Common.EnumHelper
    {
        /// <summary>
        /// 把Enum类型转成List&lt;ListItem&gt;
        /// </summary>
        /// <param name="enumType">要转换的enum类型</param>
        /// <param name="onlyName">是否只取名称不取int值</param>
        /// <returns>List&lt;ListItem&gt;</returns>
        public static List<ListItem> ConvertToListItems<T>(bool onlyName)
        {
            List<ListItem> list = new List<ListItem>();
            ListItem item;
            List<T> enList = ConvertToList<T>();
            foreach (T en in enList)
            {
                string text = en.ToString();
                int intValue = Convert.ToInt32(en);
                item = new ListItem();
                item.Text = text;
                if (onlyName)
                    item.Value = text;
                else
                    item.Value = intValue.ToString();
                list.Add(item);
            }

            return list;
        }

        /// <summary>
        /// 把Enum类型转成List&lt;ListItem&gt;
        /// </summary>
        /// <param name="enumType">要转换的enum类型</param>
        /// <returns></returns>
        public static List<ListItem> ConvertToListItems<T>()
        {
            return ConvertToListItems<T>(false);
        }
    }
}
